<!DOCTYPE html>
<html>
<head>
    <base href="/">
    <meta charset="utf-8">
    <title>个人</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all"/>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery.min.js"></script>
    <!-- Custom Theme files -->
    <!--theme-style-->
    <link href="css/style.css" rel="stylesheet" type="text/css" media="all"/>
    <!--//theme-style-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="application/x-javascript"> addEventListener("load", function () {
        setTimeout(hideURLbar, 0);
    }, false);

    function hideURLbar() {
        window.scrollTo(0, 1);
    } </script>
    <!-- start menu -->
    <link href="css/memenu.css" rel="stylesheet" type="text/css" media="all"/>
    <script type="text/javascript" src="js/memenu.js"></script>
    <script>$(document).ready(function () {
        $(".memenu").memenu();
    });</script>
    <script src="js/simpleCart.min.js"></script>
    <style>
        .main-container {margin-top: 20px;}
        .layui-nav-img {width: 40px;height: 40px;}
        .address-item {width:250px; height: 180px; margin-left: 6px; float: left; border: 1px solid #C9C5C5; border-radius: 5px; padding: 15px;margin-bottom: 10px;}
        #address::after { content: ""; display:block; clear:both; height:0px; overflow:hidden; }
        .default-address {border-color: #FF5722;}
        td, th {
            overflow-wrap: break-word;  /* 单词无法完整显示时换行 */
            white-space: normal;        /* 允许换行（覆盖默认不换行行为） */
        }
    </style>
    <style>
        .comment {
            font-family: 'Segoe UI', system-ui;
            max-width: 800px;
            margin: 10px auto;
            padding: 0 15px;
            background-color: #f8f9fa;
        }

        .comments-container {
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 1px 8px rgba(0,0,0,0.08);
            padding: 10px;
        }

        .comment-item {
            padding: 20px;
            margin: 15px 0;
            border: 1px solid #e9ecef;
            border-radius: 6px;
            position: relative;
            transition: all 0.15s ease;
        }

        .comment-item:hover {
            background-color: #f8f9fa;
        }

        .rating {
            font-size: 18px;
            color: #fa6400;
            font-weight: 600;
            position: absolute;
            left: 20px;
            top: 20px;
        }

        .product-name {
            position: absolute;
            left: 180px;
            top: 20px;
            color: #2d7ff9;
            font-size: 15px;
            max-width: 300px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .comment-time {
            color: #868e96;
            font-size: 13px;
            position: absolute;
            right: 20px;
            top: 10px;
        }

        .comment-content {
            margin-top: 16px;
            color: #495057;
            line-height: 1.5;
            font-size: 14px;
            padding: 12px 0 20px;
        }

        .delete-btn {
            position: absolute;
            right: 20px;
            bottom: 15px;
            background: #ff4d4f;
            color: white;
            border: none;
            border-radius: 4px;
            padding: 4px 12px;
            font-size: 12px;
            cursor: pointer;
            transition: opacity 0.2s;
        }

        .delete-btn:hover {
            opacity: 0.8;
        }
    </style>
</head>
<body>


<!--header-->
<div class="header">
    <div class="header-top">
        <div class="container">
            <div class="search">
                <form action="shopping/goods" style="display: flex; gap: 8px;">
                    <input type="text" placeholder="Search" name="keywords">
                    <!--                    <input type="text" value="Search " onfocus="this.value = '';"-->
                    <!--                           onblur="if (this.value == '') {this.value = 'Search';}">-->
                    <button type="button" name="searchbtn" class="layui-btn layui-btn-sm layui-btn-primary" >搜索</button>
                </form>
            </div>
            <div class="header-left">
                <ul>
                    <li><a href="shopping/userinfo">User</a></li>
                    <!--                    <li><a href="shopping/login">Login</a></li>-->
                    <!--                    <li><a href="shopping/register">Register</a></li>-->
                    <li></li>
                </ul>
                <div class="cart box_1">
                    <a href="shopping/cart">
                        <h3>
                            <div class="total">
                                <span class="simpleCart_total"></span> (<span id="simpleCart_quantity"
                                                                              class="simpleCart_quantity"></span> items)
                            </div>
                            <img src="images/cart.png" alt=""/>
                        </h3>
                    </a>
                    <p><a href="javascript:;" class="simpleCart_empty">Empty Cart</a></p>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
    <div class="container">
        <div class="head-top">
            <div class="logo">
                <a href="shopping/index"><img src="images/logo.png" alt=""></a>
            </div>
            <div class=" h_menu4">
                <ul class="memenu skyblue">
                    <li class="active grid"><a class="color8" href="shopping/index">Home</a></li>
                    <li><a class="color1" href="shopping/goods">Shop</a>

                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>

<!-- 主体容器 -->
<div class="layui-container main-container">
    <div class="layui-row">
        <!-- 左侧菜单 -->
        <div class="layui-col-md3">
            <ul class="layui-nav layui-nav-tree">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="layui-nav-title">个人中心</a>
                    <dl class="layui-nav-child">
                        <dd class="layui-this"><a _href="#orders">我的订单</a></dd>
                        <dd><a _href="#baseInfo">个人信息</a></dd>
                        <dd><a _href="#address">收货地址</a></dd>
                        <dd><a _href="#reviews">我的评价</a></dd>
                    </dl>
                </li>
            </ul>
        </div>

        <!-- 右侧内容 -->
        <div class="layui-col-md9">
            <!-- 个人信息 -->
            <div id="baseInfo" class="content-block"  style="display:none;">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">头像</label>
                        <div class="layui-input-block">
                            <img src="easyfile/upload.png" class="layui-nav-img" id="userimg">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="usertruename" value="用户名" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" id="usernickname" value="昵称" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-block">
                            <input type="tel" id="userphone" class="layui-input" value="" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" onclick="infosEdit()">修改信息</button>
                            <button type="button" class="layui-btn" onclick="passwordEdit()">修改密码</button>
                        </div>
                    </div>
                </form>
            </div>

            <!-- 收货地址 -->
            <div id="address" class="content-block" style="display:none;">
                <button class="layui-btn layui-btn-normal">新增地址</button>
                <div class="address-item default-address">
                    <p id="addressinfo">张三 138==&zwnj;****&zwnj;==8888</p>
                    <p id="addressaddress">北京市朝阳区建国路100号</p>
                    <div class="layui-btn-group">
                        <button class="layui-btn layui-btn-primary">设为默认</button>
                        <button class="layui-btn">编辑</button>
                        <button class="layui-btn layui-btn-danger">删除</button>
                    </div>
                </div>
            </div>
            <!-- 我的订单 -->
            <div id="orders" class="content-block">
                <table class="layui-table" style="width: 100%; table-layout: fixed;">
                    <colgroup>
                        <col style="width: 125px;">
                        <col style="width: 215px;">
                        <col style="width: 70px;">
                        <col style="width: 85px;">
                        <col style="width: 140px;">
                        <col style="width: 70px;">
                    </colgroup>
                    <thead>
                    <tr>
                        <th>订单号</th>
                        <th>商品信息</th>
                        <th>金额</th>
                        <th>状态</th>
                        <th>状态更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="OrderList">
                    <tr>
                        <td>暂无订单</td>
                        <td>无</td>
                        <td>¥00.00</td>
                        <td>无订单</td>
                        <td>2025-01-01 00:00:00</td>
                        <td><a class="layui-btn layui-btn-xs" onclick="shouhuo()">确认收货</a></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <!-- 我的评价 -->
            <div id="reviews" class="comment content-block comments-container" style="display:none;">
                    <!-- 示例评论1 -->
                    <div class="comment-item">
                        <div class="rating"> </div>
                        <div class="product-name"> </div>
                        <div class="comment-time"> </div>
                        <div class="comment-content">
                            暂无评论
                        </div>
<!--                        <button class="delete-btn">删除</button>-->
                    </div>

            </div>
        </div>
    </div>
</div>
<!--新增-->
<div style="display: none" id="addAddressWin" class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">省份</label>
        <div class="layui-input-inline">
            <select name="provincecode2"  lay-filter="provincecode2">
                <option value='' selected disabled>请选择</option>
            </select>
            <input type="hidden" name="province">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">城市</label>
        <div class="layui-input-inline">
            <select name="citycode2" lay-filter="citycode2">
                <option value='' selected disabled>请先选择上一级</option>
            </select>
            <input type="hidden" name="city">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">区域</label>
        <div class="layui-input-inline">
            <select name="areacode2"  lay-filter="areacode2">
                <option value='' selected disabled>请先选择上一级</option>
            </select>
            <input type="hidden" name="area">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="Address">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="name">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="telephone">
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn layui-btn-sm  layui-btn-danger" type="button" id="addAddressBtn" onclick="qrtj()">提交</button>
    </div>
</div>

<!--修改-->
<div style="display: none" id="editAddressWin" class="layui-form">
    <input type="hidden" name="upid" id="upid">
    <div class="layui-form-item">
        <label class="layui-form-label">省份</label>
        <div class="layui-input-inline">
            <select name="provincecode" lay-filter="provincecode"></select>
            <input type="hidden" name="upprovince" id="upprovince">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">城市</label>
        <div class="layui-input-inline">
            <select name="citycode"  lay-filter="citycode"></select>
            <input type="hidden" name="upcity" id="upcity">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">区域</label>
        <div class="layui-input-inline">
            <select name="areacode"  lay-filter="areacode"></select>
            <input type="hidden" name="uparea" id="uparea">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="upAddress" id="upAddress">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="upname" id="upname">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">电话</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="uptelephone" id="uptelephone">
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn layui-btn-sm  layui-btn-danger" type="button" onclick="bianjitj()">提交</button>
    </div>
</div>


<!--编辑数据表单-->
<div style="display: none" id="editinfosWin" lay-filter="editinfosWin" class="layui-form">
    <input name="userinfosId" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-inline">
            <img src="easyfile/upload.png" _id="addupload" style="width: 100px;height: 100px;cursor: pointer">
            <input type="hidden" _id="addimgurl" lay-verify="easyimg">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" id="userinfosName">账户</label>
        <div class="layui-input-inline">
            <input type="text" name="userinfosName" required lay-verify="required" placeholder="用户名" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" id="userinfosNickname">昵称</label>
        <div class="layui-input-inline">
            <input type="text" name="userinfosNickname" required lay-verify="required" placeholder="昵称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" id="userinfosTelephone">电话</label>
        <div class="layui-input-inline">
            <input type="text" name="userinfosTelephone" required lay-verify="required" placeholder="电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center">
        <button type="button" class="layui-btn layui-btn-sm" onclick="saveinfos()">保存</button>
        <button type="button" class="layui-btn layui-btn-sm" onclick="cancle()">取消</button>
    </div>
</div>

<div style="display: none" id="editpassWin" lay-filter="editinfosWin" class="layui-form">
    <input name="userpassname" type="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label" id="userpass">原密码</label>
        <div class="layui-input-inline">
            <input type="text" name="userpass" required lay-verify="required" placeholder="请输入原始密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" style="text-align: center">
        <button type="button" class="layui-btn layui-btn-sm" id="passwordconfirm" onclick="savenewpass()">确认</button>
        <button type="button" class="layui-btn layui-btn-sm" onclick="cancle()">取消</button>
    </div>
</div>

<script src="layui/layui.all.js"></script>
<script>
    const $ = layui.$;
    const form = layui.form;
    const upload = layui.upload;

    layui.use(['element', 'form'], function(){
        var element = layui.element;
        var form = layui.form;

        // 菜单切换
        $('.layui-nav-child a').click(function(e){
            e.preventDefault();
            $('.content-block').hide();
            $($(this).attr('_href')).show();
        });

    });

    function easyCart() {
        $.ajax({
            url: "cart/list",
            data: {},
            async: false,
            success: function (cart) {
                let sumprice=0;
                let i=0;
                for (i = 0; i < cart.length; i++) {
                    sumprice+=(cart[i].number*cart[i].goods.price);
                }
                sumprice=Math.ceil(sumprice * 100) / 100;
                $(".total").html("<span>￥ &nbsp;&nbsp; "+sumprice+"</span>(<span>"+i+"</span>items)");
                if(cart.length!==0){
                    $(".simpleCart_empty").text(" ");
                }
            }
        });
    }
    easyCart();

    $("[name='searchbtn']").click(function () {
        let searchtext=$("input[name='keywords']").val();
        location.href="shopping/goods?keywords="+searchtext;
    });

    function baseuserinfo(){
        $.ajax({
            url: "user/getbyid",
            data: {},
            async: false,
            success: function (data) {
                document.getElementById('userimg').src = data.imgurl;
                document.getElementById('usertruename').value=data.name;
                document.getElementById('usernickname').value=data.nickname;
                document.getElementById('userphone').value=data.telephone;
                $("[name='userinfosId']").val(data.id);
                $("[name='userinfosName']").val(data.name);
                $("[name='userinfosNickname']").val(data.nickname);
                $("[name='userinfosTelephone']").val(data.telephone);
                $("[_id='addupload']").attr("src",data.imgurl);
                $("[name='userpassname']").val(data.name);
            }
        });
    }
    baseuserinfo();

    function useraddress(){
        $.ajax({
            url: "user/getaddress",
            data: {},
            async: false,
            success: function (data) {
                $("#address").empty();
                for (let i = 0; i < data.length; i++) {
                    if(data[i].isdefault===1){
                        $("#address").append("<div class='address-item default-address' style='background-color: rgba(255,160,122,0.48)'><p id='addressname'>"+data[i].name+"</p><p id='addressphone'>"+data[i].telephone+"</p><p id='addressaddress'>"
                            +data[i].city+"-"+data[i].address+"</p><br/><br/><div class='layui-btn-group'><button class='layui-btn' type='button' onclick='bianji("
                            +data[i].id+")'>编辑</button><button type='button' class='layui-btn layui-btn-danger' onclick='shanchu("+data[i].id+")'>删除</button></div></div>");
                        continue;
                    }
                    $("#address").append("<div class='address-item default-address'><div onclick='moren("+data[i].id+")'><p id='addressname'>"+data[i].name+"</p><p id='addressphone'>"+data[i].telephone+"</p><p id='addressaddress'>"
                        +data[i].city+"-"+data[i].address+"</p><br/><br/></div><div class='layui-btn-group'><button class='layui-btn' type='button' onclick='bianji("
                        +data[i].id+")'>编辑</button><button type='button' class='layui-btn layui-btn-danger' onclick='shanchu("+data[i].id+")'>删除</button></div></div>");
                }
                if (data.length < 4) {
                    $("#address").append("<div class='address-item default-address' style='display: flex; flex-direction: column; align-items: center; justify-content: center;' onclick='xinzeng()'><p id='emptyaddress'>+</p><p id='newaddress'>新增地址</p></div>");
                }
            }
        });
    }
    useraddress();
    function xinzeng(){
        layer.open({
            type: 1,
            area: ['500px', '600px'],
            content:$("#addAddressWin")
        });

    }
    function qrtj(){
        let address= {};
        let province=$("input[name='province']").val();
        let city=$("input[name='city']").val();
        let area=$("input[name='area']").val();
        let Address=$("input[name='Address']").val();
        let name=$("input[name='name']").val();
        let telephone=$("input[name='telephone']").val();
        if (province){address.province=province;}else{layer.msg("请选择省份"); return false;}
        if (city){address.city=city;}else{layer.msg("请选择城市"); return false;}
        if (area){address.area=area;}else{layer.msg("请选择地区"); return false;}
        if (Address){address.address=Address;}else{layer.msg("请填写详细地区"); return false;}
        if (name){address.name=name;}else{layer.msg("请填写收货人"); return false;}
        if (telephone){address.telephone=telephone;}else{layer.msg("请填写联系电话"); return false;}
        layer.confirm("确认地址无误?",function(index) {
            //点击确认后执行函数
            layer.close(index);
            layer.closeAll();
            $.ajax({
                url: "user/addaddress",
                data: address,
                async: false,
                success: function (data) {
                    useraddress();
                }

            });
        })

    }
    function moren(t){

        layer.confirm("确认修改默认地址?",function(index) {
            layer.close(index);
            $.ajax({
                url: "user/defaultaddress",
                data: {id:t},
                async: false,
                success: function (data) {
                    useraddress();
                }
            });
        });
    }
    function bianji(t){
        $.ajax({
            url: "user/getaddressbyid",
            data: {id: t},
            async: false,
            success: function (data) {
                document.getElementById('upid').value = data.id;
                document.getElementById('upprovince').value = data.province;
                document.getElementById('upcity').value = data.city;
                document.getElementById('uparea').value = data.area;
                document.getElementById('upAddress').value = data.address;
                document.getElementById('upname').value = data.name;
                document.getElementById('uptelephone').value = data.telephone;
            }
        });

        layer.open({
            type: 1,
            area: ['500px', '600px'],
            content:$("#editAddressWin")
        });
    }

    function bianjitj(){
        let address= {};
        let id= $("input[name='upid']").val();
        let province=$("input[name='upprovince']").val();
        let city=$("input[name='upcity']").val();
        let area=$("input[name='uparea']").val();
        let Address=$("input[name='upAddress']").val();
        let name=$("input[name='upname']").val();
        let telephone=$("input[name='uptelephone']").val();
        if (id){address.id=id;}else{layer.msg("收货地址异常，请联系管理员"); return false;}
        if (province){address.province=province;}else{layer.msg("请选择省份"); return false;}
        if (city){address.city=city;}else{layer.msg("请选择城市"); return false;}
        if (area){address.area=area;}else{layer.msg("请选择地区"); return false;}
        if (Address){address.address=Address;}else{layer.msg("请填写详细地区"); return false;}
        if (name){address.name=name;}else{layer.msg("请填写收货人"); return false;}
        if (telephone){address.telephone=telephone;}else{layer.msg("请填写联系电话"); return false;}
        layer.confirm("确认地址无误?",function(index) {
            layer.close(index);
            layer.closeAll();
            console.log(address);
            $.ajax({
                url: "user/editaddress",
                data: address,
                async: false,
                success: function (data) {
                    useraddress();
                }
            });
        })
    }


    function shanchu(t){
        layer.confirm("确认删除?",function(index) {
            layer.close(index);
            $.ajax({
                url: "user/deleteaddress",
                data: {id:t},
                async: false,
                success: function (data) {
                    useraddress();
                    layer.msg("成功删除"+data+"条收货地址");
                }
            });
        });
    }

    const stateMap = {
        0: "未支付",
        1: "待发货",
        2: "已发货",
        3: "已签收",
        4: "订单结束",
        6: "订单超时已取消"
    };
    const stateTodo = {
        0: "去支付",
        1: "等待发货",
        2: "确认收货",
        3: "已收货",
        4: "订单结束",
        6: "已取消"
    };
    const stateColor = {
        0: "layui-btn-warm",
        1: "layui-btn-normal",
        2: "layui-btn-danger",
        3: "layui-btn-primary",
        4: "layui-btn-primary",
        6: "layui-btn-disabled"
    };


    function getOrder(){
        $.ajax({
            url: "order/easyOrder",
            data: {},
            async: false,
            success: function (data) {
                $("#OrderList").empty();

                for(let i=0;i<data.length;i++){
                    let state = stateMap[data[i].state] || '未知状态';
                    let todo = stateTodo[data[i].state] || '订单异常';
                    let Color = stateColor[data[i].state] || 'layui-btn-disabled';
                    let name = "";
                    for(let j=0;j<data[i].name.length;j++){
                        name += (data[i].name[j]+"；");
                    }
                    $("#OrderList").append("<tr><td>"+data[i].code+"</td><td>"+name+"</td><td>¥"
                        +data[i].money+"</td><td>"+state+"</td><td>"+data[i].updatetime
                        +"</td><td><a class='layui-btn layui-btn-xs "+Color+"' onclick='caozuo("+data[i].id+","+data[i].state+")'>"+todo+"</a></td></tr>");
                }
            }
        });
    }
    getOrder();

    function caozuo(id,state){
        if(state===0){
            zhifu(id);
        }else if(state===1){
            layer.msg("商品即将发货");
        }else if(state===2){
            layer.confirm("确认收货?",function(index) {
                //点击确认后执行函数
                layer.close(index);
                shouhuo(id);
                getOrder();
            });
        }else if(state===3) {
            layer.msg("已收货");
        }else if(state===4){
            layer.msg("订单已结束");
        }else if(state===6){
            layer.msg("订单已取消");
        }else{
            layer.msg("订单异常,请联系管理员")
        }
    }
    function shouhuo(id){
        $.ajax({
            url: "order/shouhuo",
            data: {orderid:id},
            async: false,
            success: function (data) {
                getOrder();
            }
        });
    }
    function zhifu(id){
        location.href = "shopping/payment?orderid="+id;
        getOrder();
    }






    showArea(100000, $("[name='provincecode']"));
    showArea(100000, $("[name='provincecode2']"));

    function showArea(code, $dom) {
        $.ajax({
            url: "https://restapi.amap.com/v3/config/district",
            data: {key: 'd5e466c74f37e2b1f89163a68a161ea7', keywords: code},
            success: function (result) {
                let children = result.districts[0].districts;
                $dom.empty();
                $dom.append($("<option selected disabled >请选择</option>"));
                for (let i = 0; i < children.length; i++) {
                    $dom.append($("<option value='" + children[i].adcode + "'>" + children[i].name + "</option>"));
                }
                form.render("select");
            }
        });
    }
    form.on('select(provincecode)', function (data) {
        let provincecode = data.value; //得到被选中的值
        showArea(provincecode, $("[name='citycode']"));
        showArea(provincecode, $("[name='citycode']"));
        let provincename = $(data.othis).find("input").val();
        $("[name='upprovince']").val(provincename);
        $("[name='upcity']").val(null);
        $("[name='uparea']").val(null);
    });
    form.on('select(citycode)', function (data) {
        let citycode = data.value; //得到被选中的值
        showArea(citycode, $("[name='areacode']"));
        let cityname = $(data.othis).find("input").val();
        $("[name='upcity']").val(cityname);
        $("[name='uparea']").val(null);
    });
    form.on('select(areacode)', function (data) {
        let areaname = $(data.othis).find("input").val();
        $("[name='uparea']").val(areaname);
    });

    form.on('select(provincecode2)', function (data) {
        let provincecode2 = data.value; //得到被选中的值
        showArea(provincecode2, $("[name='citycode2']"));
        let provincename2 = $(data.othis).find("input").val();
        $("[name='province']").val(provincename2);
        $("[name='city']").val(null);
        $("[name='area']").val(null);
    });
    form.on('select(citycode2)', function (data) {
        let citycode2 = data.value; //得到被选中的值
        showArea(citycode2, $("[name='areacode2']"));
        let cityname2 = $(data.othis).find("input").val();
        $("[name='city']").val(cityname2);
        $("[name='area']").val(null);
    });
    form.on('select(areacode2)', function (data) {
        let areaname2 = $(data.othis).find("input").val();
        $("[name='area']").val(areaname2);
    });

    function infosEdit(){
        layer.open({
            type: 1,
            tittle:'编辑分类',
            area: ['400px', '400px'],
            content:$("#editinfosWin")
        });
    }

    function cancle(){
        layer.closeAll();
    }
    function saveinfos(){
        let user={};
        user.id = $("[name='userinfosId']").val();
        user.imgurl = $("[_id='addimgurl']").val();
        user.nickname = $("[name='userinfosNickname']").val();
        user.telephone = $("[name='userinfosTelephone']").val();
        console.log(user);
        $.ajax({
            url:'user/updateUserById',
            data:user,
            async:false,
            success:function(result) {
                layer.closeAll();
                layer.msg("修改成功");
                baseuserinfo();
            }
        });
    }
    function passwordEdit(){
        layer.open({
            type: 1,
            tittle:'原始密码',
            area: ['400px', '400px'],
            content:$("#editpassWin")
        });
    }
    function savenewpass(){
        let user={};
        user.name=$("[name='userpassname']").val();
        user.password=$("[name='userpass']").val();
        $.ajax({
            url:'shopping/passchecker',
            data:user,
            async:false,
            success:function(result) {
                if (result == "success") {
                    // layer.closeAll();
                    $("#userpass").text("新密码");
                    $("[name='userpass']").attr("placeholder","请输入新密码").val("");
                    $("#passwordconfirm").attr("onclick","passwordfinallyconfirm()");

                }else{
                    layer.msg("密码错误，请重新输入旧密码");
                }
            }
        });
    }
    function passwordfinallyconfirm(){
        let password=$("[name='userpass']").val();
        $.ajax({
            url:'user/newpass',
            data:password,
            async:false,
            success:function(result) {
                layer.closeAll();
                layer.msg("密码成功设置为：\""+password+"\"，请妥善保存。");
            }
        });
    }



    //文件上传
    upload.render({
        elem:"[_id='addupload']",
        url:'file/upload',
        done: function(result){
            //上传成功,返回的是一个什么结果?
            //res.data[0].src(文件上传地址)
            console.log(result);
            let url=result.data[0].src;
            $("[_id='addupload']").attr("src",url);
            $("[_id='addimgurl']").val(url);
        },
        error:function(res){
            console.log(res);
            layer.msg("上传失败",{icon:2});
        }

    });

    userReview();
    function userReview(){
        $.ajax({
            url:'goods/getReviewByUserid',
            data:{},
            async:false,
            success:function(res){
                if(res.length>0){
                    $(".comments-container").empty();
                    for(let i=0;i<res.length;i++){
                        $(".comments-container").append("<div class='comment-item'><div><ul class='star-footer rating' id='grade"+res[i].id
                            +"'></ul></div><div class='product-name'><a href='shopping/single?id="+res[i].goodsid+"'> "+res[i].goodsname
                            +"</a></div><div class='comment-time'>"+res[i].reviewtime +"</div><div class='comment-content'>"+res[i].content
                            +"</div><button class='delete-btn' onclick='delrew("+res[i].id+")'>删除</button></div>");
                        let rate="#grade"+res[i].id;
                        for(let j=0;j<res[i].grade;j++){
                            $(rate).append("<li><i></i></li>");
                        }
                    }
                }else{
                    $(".comments-container").empty().append("<div> 18个月内暂无其他评论 </div>");
                }

            }
        });
    }
    function delrew(id){
            $.ajax({
                url:'goods/delReviewById',
                data:{id:id},
                async:false,
                success:function(res){
                    layer.msg("成功删除"+res+"条记录");
                    userReview();
                }
            });
    }
</script>

</body>
</html>
